package weixin.processer.event;

import java.util.ArrayList;
import java.util.List;

import models.Article;
import models.ArticleMulti;
import models.Reply;
import models.Weixin;
import models.WeixinProp;
import net.ufrog.common.utils.Strings;
import play.Play;
import utils.json.Gsons;
import weixin.Converters;
import weixin.WXMessage;
import weixin.WXMessage.Item;

/**
 * @author ultrafrog
 * @version 1.0, 2014-11-12
 * @since 1.0
 */
public class WelcomeEventProcesser extends WXEventProcesser {

	/* (non-Javadoc)
	 * @see weixin.processer.event.WXEventProcesser#process(weixin.WXMessage, weixin.WXMessage)
	 */
	@Override
	public Boolean process(WXMessage wxmsg, WXMessage bkmsg) {
		// 读取数据
		Weixin weixin = Weixin.find("byOriginalCode", wxmsg.toUserName).first();
		WeixinProp wxprop = WeixinProp.find("byWeixinAndCode", weixin.id, WeixinProp.Code.WELCOME).first();
		
		// 判断并处理欢迎信息
		if (wxprop != null) {
			Reply reply = Gsons.fromJson(wxprop.value, Reply.class);
			Converters.replyToMessage(reply, bkmsg);
		}
		return Boolean.TRUE;
	}
}
